package thread;

public class Demo7 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while(true) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //获取 t 的存活状态
        System.out.println(t.isAlive());

        t.start();

        Thread.sleep(1000);
        //此时 t 还在运行中
        System.out.println(t.isAlive());

        Thread.sleep(4000);
        //此时 t 已经结束了
        System.out.println(t.isAlive());
    }
}
